﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using App.Interface;
using App.Model;
using Newtonsoft.Json;

namespace App.Realization
{
    public class PingShen : IPingShen
    {
        public string GetKaoHeBiaoInfo(int mkhbid, string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetKaoHeBiaoInfo?mkhbid=" + mkhbid + "&username=" + username);
            return result;
        }

        public string GetKaoHeBiaos(string username,string khusername)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetKaoHeBiaos?username=" + username+ "&khusername="+ khusername);
            if (string.IsNullOrEmpty(result))
            {
                return string.Empty;
            }
            Newtonsoft.Json.Converters.IsoDateTimeConverter convert = new Newtonsoft.Json.Converters.IsoDateTimeConverter();
            convert.DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";
            var DynamicObject = JsonConvert.DeserializeObject<List<dynamic>>(result, convert);
            List<MyKaoHeBiao> lst=new List<MyKaoHeBiao>();
            foreach (var item  in DynamicObject)
            {
                var tt = Mappeing.ToMyKaoHeBiao(item);
                lst.Add(tt);
            }
            string mykaohebiaostr = JsonConvert.SerializeObject(lst);
            return mykaohebiaostr;
        }

        public string GetKaoHeBiaoInfoGZJH(int mkhbid, string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetKaoHeBiaoInfoGongZuoJiHua?mkhbid=" + mkhbid + "&username=" + username);
            return result;
        }

        public string GetKaoHeFanWeiKHB(string datetimes, int mbid, string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetKaoHeFanWeiKHB?mbid=" + mbid + "&username=" + username + "&datetimes=" + datetimes);
            return result;
        }
        public string GetAllIngKaoHeBiaos(int mbid, string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetAllIngKaoHeBiaos?mbid=" + mbid + "&username=" + username);
            return result;
        }

        public string GetKaoHeRenYuanList(string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetKaoHeRenYuanList?username=" + username);
            return result;
        }

        public void SavePingShenJieGuo(string str)
        {
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/SavePingShengJieGuo", str);
        }

        public void CreateKaoHeDeFenBiao(int ksid)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/CreateKaoHuiZong?ksid=" + ksid);
        }

        public string GetXiaShuZhiWuYuanGong(string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetXiaShuZhiWuYuanGong?username=" + username);
            return result;
        }

        public void QueRenXiaShuDeFen(string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/QueRenXiaShuDeFen?username=" + username);
        }

        public string GetKaoHeWeiTiao(string username, int mbid)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetKaoHeWeiTiao?username=" + username + "&mbid=" + mbid);
            return result;
        }

        public string GetMyKaoHeBiaosBydatetime(string username, string sssj)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetMyKaoHeBiaoBydatetime?username=" + username + "&datetimes=" + sssj);
            return result;
        }

        public void UpdateKaoHeBiao_TuiHui(int mkhbid, string username, string yijian)
        {
            dynamic obj = new { mkhbid = mkhbid, username = username, yijian = yijian };
            string postData = JsonConvert.SerializeObject(obj);
            var result = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/UpdateKaoHeBiao_TuiHui", postData);
        }

        public string GetAllIngKaoHeBiaosByKeShenHe(string datetimes, int mbid, string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetKaoHeBiaosByKeShenHe?mbid=" + mbid + "&username=" + username + "&datetimes=" + datetimes);
            return result;
        }

        public string GetKaoHeHuiZongMoBan(int mbid)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetKaoHeBiaoMoBan?mbid=" + mbid);
            return result;
        }

        public string GetKaoHeHuiZongDeFen(int mbid, string sssj)
        {
            //var sssj = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddMonths(-1).ToShortDateString();//上个月1号
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetKaoHeDeFen?mbid=" + mbid + "&sssj=" + sssj);
            return result;
        }

        public string GetPingFenRenYuanList(int mkhbid)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetPingFenRenYuanList?mkhbid=" + mkhbid);
            return result;
        }

        public void DelPingFenRenYuan(int mkhbid, string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/DelPingFen?mkhbid=" + mkhbid + "&username=" + username);
        }

        public string GetBeiKaoHeBiaos(string username)
        {
            var result = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/PingShen/GetBeiKaoHeBiaos?username=" + username);
            return result;
        }
    }
}
